﻿using TimingWheel;

namespace 时间轮
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            // 定义一个秒级时间轮
            var timer = TimingWheelTimer.Build(TimeSpan.FromSeconds(1), 100);
            timer.Start();


            // 添加延时任务
            var task1 = timer.AddTask(TimeSpan.FromMilliseconds(600), () =>
            {
                Console.WriteLine($"{DateTime.Now}, Task1: 执行");
            });
            //var task2 = timer.AddTask(TimeSpan.FromSeconds(5), () =>
            //{
            //    Console.WriteLine($"{DateTime.Now}, Task2: 执行");
            //    throw new Exception();
            //});

            //Console.WriteLine($"{DateTime.Now}, Task1: {task1.TaskStatus}");
            ////Console.WriteLine($"{DateTime.Now}, Task2: {task2.TaskStatus}");

            //// 等待到期执行
            //await Task.Delay(TimeSpan.FromSeconds(6));

            //Console.WriteLine($"{DateTime.Now}, Task1: {task1.TaskStatus}");
            //Console.WriteLine($"{DateTime.Now}, Task2: {task2.TaskStatus}");

            //timer.Stop();


            Console.ReadKey();
        }
    }
}
